import { combineReducers } from 'redux';

// imports all file except index.js
const req = require.context('.', true, /^(?!.\/index)(?!.\/__tests__).*.js$/);

const reducersModules = {};
const sagaModules = [];

req.keys().forEach(key => {
  const regex = /.\/(.*?).js$/;
  const moduleName = regex.test(key) && key.match(regex)[1];
  reducersModules[moduleName] = req(key).default;
  sagaModules.push(req(key).RootSaga);
});

export default {
  reducer: combineReducers(reducersModules),
  sagas: sagaModules
};
